﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing.Printing;

namespace _180FrameWork.Common
{
    public class PrinterHelper
    {
        /// <summary>
        /// 获取所有安装打印机
        /// </summary>
        /// <returns></returns>
        public static string[] GetPrinterList()
        {
            IList<string> printerlist = new List<string>();
            string CurrentPrinter = "";
            foreach (string printer in PrinterSettings.InstalledPrinters)
            {
                if (printer == GetCurrentPrinter())
                {
                    CurrentPrinter = printer;
                }
                else
                {
                    printerlist.Add(printer);
                }
            }
            if (CurrentPrinter != "")
            {
                printerlist.Insert(0, CurrentPrinter);
            }
            return printerlist.ToArray();
        }
        /// <summary>
        /// 获取当前打印机
        /// </summary>
        /// <returns></returns>
        public static string GetCurrentPrinter()
        {
            PrintDocument pd = new PrintDocument();
            return pd.PrinterSettings.PrinterName;
        }
    }
}
